package pro.lepers.portfolio.view.contents.portfolio.thumb {
	import fr.digitas.flowearth.mvc.address.structs.INode;

	import pro.lepers.portfolio.view.contents.portfolio.content.ThumbContent;
	import pro.lepers.portfolio.view.contents.portfolio.data.contents.AbstractContentData;

	import flash.events.MouseEvent;

	/**
	 * @author Pierre Lepers
	 */
	public class ContentHolder extends Holder {

		
		public function ContentHolder( pcData : AbstractContentData, node : INode, w : int, h : int ) {
			_node = node;
			_contentData = pcData;
			super( w , h );
			
			_container.addChild( _content = _contentData.getView() );
			_content.setSize( _width , _height );
			addEventListener( MouseEvent.CLICK, needActivation );
			useHandCursor = buttonMode = true;
			mouseChildren = false;
		}
		
		public function get content() : ThumbContent {
			return _content;
		}
		
		
		public function dispose () : void {
			_content.dispose( );
			_container.removeChild( _content );
			_contentData = null;
			removeChild( _container );
		}

		override public function set locked (locked : Boolean) : void {
			super.locked = locked;
			_content.highQuality = locked;
		}

		override protected function setSize(w : int, h : int) : void {
			super.setSize( w , h );
			_content.setSize( w, h );
		}

		public function focus () : void {
			_content.focus();
		}
		public function unfocus () : void {
			_content.unfocus();
		}

		public function focused () : void {
			if( _focused ) return;
			_focused = true;
			_content.focused();
			removeEventListener( MouseEvent.CLICK, needActivation );
			useHandCursor = buttonMode = false;
			mouseChildren = true;
		}

		public function unfocused () : void {
			if( ! _focused ) return;
			_focused = false;
			_content.unfocused();
			addEventListener( MouseEvent.CLICK, needActivation );
			useHandCursor = buttonMode = true;
			mouseChildren = false;
		}

		
		public function shown () : void {
			if( !_hidded ) return;
			_hidded = false;
			_content.shown();
		}
		
		public function hidded () : void {
			if( _hidded ) return;
			_hidded = true;
			_content.hidded();
		}


		protected var _contentData : AbstractContentData;

		private function needActivation (event : MouseEvent) : void {
			trace(" ContentHolder _node.activate();" );
			_node.activate();
		}

		private var _content : ThumbContent;
		
		private var _focused : Boolean = false;

		private var _hidded : Boolean = true;
		
		private var _node : INode;
	}
}
